package src.java.medium;

public class Solution45 {
    public static int findMaxLen(int[] nums, int start, int end) {
        int maxLen = 0;
        for (int i = start; i <= end; i++) {
            if (nums[i] + i > maxLen) {
                maxLen = nums[i] + i;
            }
        }
        return maxLen;
    }
    public int jump(int[] nums) {
        int minCount = 1;
        if(nums.length == 1) return 0;
        if (nums[0] >= nums.length - 1) return minCount;
        int start = 1;
        int end = findMaxLen(nums, 0, 0);
        for (int i = 1; i < nums.length; i++) {
            int temp = end;
            end = findMaxLen(nums, start, end);
            minCount++;
            if (end >= nums.length - 1) return minCount;
            start = temp;
        }
        return 0;
    }
}
